package com.xbs.controller.backstage;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xbs.controller.base.BaseServlet;
import com.xbs.controller.enterprise.DateJsonValueProcessor;
import com.xbs.entity.ModelManageEntity;
import com.xbs.service.selfdriving.ModelManageService;

import net.sf.json.JSONArray;
import net.sf.json.JsonConfig;
import net.sf.json.util.CycleDetectionStrategy;

/**
 * 车型管理
 * @author Administrator
 *
 */
@WebServlet("/backstage/modelmanageservlet1")
public class ModelManage1Servlet extends BaseServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String modelid = req.getParameter("modelid");
		ModelManageService modelManageService = new ModelManageService();
		List<ModelManageEntity> modelManagelist = modelManageService.selAll1(modelid);
		JsonConfig jsonConfig = new JsonConfig();   
		jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);   
		jsonConfig.registerJsonBeanProcessor(java.sql.Date.class, new DateJsonValueProcessor());  
		jsonConfig.setExcludes(new String[]{"handler","hibernateLazyInitializer"}); 
		JSONArray jsonArray = JSONArray.fromObject(modelManagelist, jsonConfig);
		resp.getWriter().print(jsonArray.toString());
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String id = req.getParameter("id1");
		String name = req.getParameter("name1");
		String type = req.getParameter("type1");
		String year = req.getParameter("year1");
		int seating = Integer.parseInt(req.getParameter("seating1"));
		int number = Integer.parseInt(req.getParameter("number1"));
		String fuel = req.getParameter("fuel1");
		String gps = req.getParameter("gps1");
		String seat = req.getParameter("seat1");
		String image = req.getParameter("image1");
		double cash = Double.valueOf(req.getParameter("cash1")).doubleValue();
		double insurance = Double.valueOf(req.getParameter("insurance1")).doubleValue();
		double discount = Double.valueOf(req.getParameter("discount1")).doubleValue();
		double pledge = Double.valueOf(req.getParameter("pledge1")).doubleValue();
		ModelManageService modelManageService = new ModelManageService();
		modelManageService.insert(id, name, type, year, seating, number, fuel, gps, seat, image, cash, insurance, discount, pledge);
		req.getRequestDispatcher("/backstage/modelmanageservlet").forward(req, resp);
	}
}
